package com.rtx.edi.platform.dash.error.controller;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rtx.edi.model.error.dto.ApiSkuErrorDto;
import com.rtx.edi.model.error.po.ApiSkuError;
import com.rtx.edi.model.response.EdiResponse;
import com.rtx.edi.platform.dash.error.service.PlSkuErrorService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = {"sku错误信息"})
@RestController
@RequestMapping("/v1/plApiskuError")
public class PlApiSkuErrorController {
	
	@Autowired
	private PlSkuErrorService plSkuErrorService;
	
	@ApiOperation(value = "sku错误信息列表", notes = "分页获取sku错误信息")
    @PostMapping("qryApiSkuError")
	public EdiResponse qryApiSkuError(@RequestBody ApiSkuError dto) {
		Page<ApiSkuError> pageParam = new Page<>(dto.getPageNum(),dto.getPageSize());
		plSkuErrorService.selectApiSkuError("enterprise",pageParam,dto);
		return EdiResponse.success().data("page",pageParam);
	}
	
	
	@ApiOperation(value = "sku错误信息列表", notes = "根据id查询sku错误信息")
    @PostMapping("qryApiSkuErrorById")
	public EdiResponse qryApiSkuErrorById(@RequestBody ApiSkuError dto) {
		return EdiResponse.success().data("item",plSkuErrorService.getById("enterprise",dto.getSerialkey()+""));
	}
	
	
	@ApiOperation(value = "标记成功", notes = "标记成功")
    @PostMapping("marksucc")
	public EdiResponse markSuccApiSkuError(@RequestBody List<ApiSkuError> list) {
		try {
			
			return EdiResponse.success();
		} catch (Exception e) {
			return EdiResponse.failed().returnMgr(e.getMessage());
		}
		
		
	}
	
	@ApiOperation(value = "SKU重发", notes = "SKU重发")
    @PostMapping("resend")
	public EdiResponse resend(@RequestBody List<ApiSkuError> list) {
		try {
			for (ApiSkuError dto :list) {
				plSkuErrorService.reHandle("enterprise", dto);
			}
			return EdiResponse.success();
		} catch (Exception e) {
			return EdiResponse.failed().returnMgr(e.getMessage());
		}

	}
	
	@ApiOperation(value = "拉取k3物料", notes = "拉取k3物料")
    @PostMapping("requestk3sku")
	public EdiResponse requestK3SKU(@RequestBody String requestStr) {
		String res ="";
		try {
			res = plSkuErrorService.requestK3SKU("ris_edi", requestStr);
		} catch (Exception e) {
			return EdiResponse.failed().returnMgr(e.getMessage());
		}
		return EdiResponse.success().data("item",res);
	}
}
